package com.vercon.mobilesafe74.activity;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.vercon.mobilesafe74.R;
import com.vercon.mobilesafe74.util.ConstantValue;
import com.vercon.mobilesafe74.util.SpUtil;
import com.vercon.mobilesafe74.view.SettingItemView;

public class SettingActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);

        //1.初始化设置更新的UI
        initUpdate();
    }

    private void initUpdate() {
        //SettingItemView自定义的view
        final SettingItemView siv_update = findViewById(R.id.siv_update);
        //TODO 获取之前设置好的状态
        boolean open_update = SpUtil.getBoolean(this, ConstantValue.OPEN_UPDATE, false);
        //状态根据上一次存储的结果去做决定
        siv_update.setCheck(open_update);
        siv_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //判断是否选中
                boolean isCheck = siv_update.isCheck();
                //2.将原有状态取反
                siv_update.setCheck(!isCheck);
                //将改变的状态存储在sp里面
                SpUtil.putBoolean(getApplicationContext(),ConstantValue.OPEN_UPDATE,!isCheck);
            }
        });
    }
}
